<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Event extends CI_Controller {
	
	public function index() { }
	
	public function getEvents() {
		$idArr = $this->input->post('arr');
		$this->load->model('Events_model');

		if($idArr) {
			$ids = array();
			foreach($idArr as $str) {
				$id = new MongoId($str);
				array_push($ids, $id);
			}
			$cursor = $this->Events_model->getEventsArr($ids);
			$cursor->sort(array('eventName' => 1));
			$arr = array();
			foreach (iterator_to_array($cursor) as $k) {
				array_push($arr, $k);
			}
			echo json_encode($arr);
			return;
		}
		else {
			$cursor = $this->Events_model->getEventData();
			$cursor->sort(array('eventName' => 1));
			$arr = array();
			foreach (iterator_to_array($cursor) as $k) {
				array_push($arr, $k);
			}
			echo json_encode($arr);
			return;
		}
	}

}
